*For REStat paper "Breastfeeding and Children's Early Cognitive Outcomes."

/* PSID DATA CENTER *****************************************************
   JOBID            : 126280                            
   OUTPUT_DATA_TYPE : ASCII                             
   STATEMENTS       : SAS Statements                    
   N_OF_VARIABLES   : 14                                
   N_OF_OBSERVATIONS: 3563                              
   MAX_REC_LENGTH   : 49                                
   DATE & TIME      : May 19, 2011 @ 11:18:43
************************************************************************/
libname dd 'X:\Donnanew';

FILENAME mapids "X:\Donnanew\mapids.txt" ;


DATA x ;
   ATTRIB
      ER30001  FORMAT=F4.   LABEL="CHILD: 1968 INTERVI_EW NUMBER"           
      ER30002  FORMAT=F3.   LABEL="CHILD: PERSON NUMBER 68"                 
      PCGID_97 FORMAT=F4.   LABEL="PCG 1997: 1968 INTERVIEW NUMBER"         
      PCGPN_97 FORMAT=F3.   LABEL="PCG 1997: PERSON NUMBER 68"              
      OCGID_97 FORMAT=F4.   LABEL="OCG 1997: 1968 INTERVIEW NUMBER"         
      OCGPN_97 FORMAT=F3.   LABEL="OCG 1997: PERSON NUMBER 68"              
      PCGID_02 FORMAT=F4.   LABEL="PCG 2002: 1968 INTERVIEW NUMBER"         
      PCGPN_02 FORMAT=F3.   LABEL="PCG 2002: PERSON NUMBER 68"              
      OCGID_02 FORMAT=F4.   LABEL="OCG 2002: 1968 INTERVIEW NUMBER"         
      OCGPN_02 FORMAT=F3.   LABEL="OCG 2002: PERSON NUMBER 68"              
      PCGID_07 FORMAT=F4.   LABEL="PCG 2007: 1968 INTERVIEW NUMBER"         
      PCGPN_07 FORMAT=F3.   LABEL="PCG 2007: PERSON NUMBER 68"              
      OCGID_07 FORMAT=F4.   LABEL="OCG 2007: 1968 INTERVIEW NUMBER"         
      OCGPN_07 FORMAT=F3.   LABEL="OCG 2007: PERSON NUMBER 68"              
   ;
   INFILE mapids LRECL = 49 ; 
   INPUT 
      ER30001      1 - 4     ER30002      5 - 7     PCGID_97     8 - 11   
      PCGPN_97    12 - 14    OCGID_97    15 - 18    OCGPN_97    19 - 21   
      PCGID_02    22 - 25    PCGPN_02    26 - 28    OCGID_02    29 - 32   
      OCGPN_02    33 - 35    PCGID_07    36 - 39    PCGPN_07    40 - 42   
      OCGID_07    43 - 46    OCGPN_07    47 - 49   
   ;
data y;
set x;
keep childid pcg97id;


childid = er30001*1000 + er30002;
pcg97id = PCGID_97*1000 + PCGPN_97;

proc sort;  by childid;

data z;
set dd.momdadid;

proc sort;  by childid;  


data dd.mdid2;
merge y z;  by childid;

**note, whole purpose of this is to make sure momid and pcg97id are the same if pcg is bio mom.  It turns out
**there are two extra bio mom ids in pcg so I'm going to use that;

proc means;
run;
proc print;
run;
